<?php

namespace app\common\service\coupon\sync_channel;

use  api\channel\coupon\JingChongHandler;


/**
 * 鲸充Api
 * @document https://liaosp-document.oss-cn-hangzhou.aliyuncs.com/%E4%B8%B4%E4%B8%8B/%E9%B2%B8%E5%85%85%20%EF%BC%88%E6%9D%83%E7%9B%8A%EF%BC%89%E5%AF%B9%E6%8E%A5%E6%96%87%E6%A1%A3.doc
 */
class JingChongChannel extends Base
{
    const CHANNEL_NAME = 'JingChong';

    /**
     * @var JingChongHandler $jingchong 鲸充具体请求接口
     */
    public $jingchong;

    /**
     * @var object $supplier 亿奇达渠道信息
     */
    public $supplier;

    /**
     *初始化构造函数
     */
    public function __construct()
    {
        $this->jingchong = new JingChongHandler();
        $this->supplier = $this->jingchong->getSupplier();
    }

    /**
     * 分类处理
     * [[origin_id:1,name:'热门分类']]
     * eg:热门影视
     */
    public function getCate():array
    {
        return [];
    }

    /**
     *品牌
     * [[origin_id:1,name:'爱奇艺会员']]
     * eg 爱奇艺
     */
    function getBrand()
    {
        // TODO: Implement getBrand() method.
    }

    /**
     * 类型 黄金会员
     * @return mixed
     * eg 黄金会员
     */
    function getType()
    {
        // TODO: Implement getType() method.
    }


    /**
     * 具体产品（第一次拉取渠道商的时候处理）
     * eg 月卡 30天卡
     */
    function getProduct()
    {
        // TODO: Implement getProduct() method.
    }

    /**
     * 渠道产品（对应的渠道商产品）
     * eg 鲸充 or other
     */
    function getChannelProduct()
    {
        $res = $this->jingchong->queryAllProduct();
        if ($res['code'] != 200) {
            return web_request([],false, 0, '请稍后再同步');
        }
        if ($productChannels = $res['data']) {
            foreach ($productChannels as $productChannel) {
                $productChannel['type'] = self::CHANNEL_NAME;
                $productChannel['name'] = $productChannel['name'];
                $productChannel['supplier_id'] = $this->supplier->id;
                $productChannel['origin_id'] = $productChannel['id'];
                $productChannel['sale_price'] = yuan2fen($productChannel['price']) ?? 0;  //单位是三位小数
                $productChannel['cost_price'] = yuan2fen($productChannel['price']) ?? 0;  //单位是三位小数
                $productChannel['market_price'] = yuan2fen($productChannel['price']) ?? 0;//平台售价？？
                $productChannel['extend'] = json_encode($productChannel, JSON_UNESCAPED_UNICODE);
                $this->productChannels[] = $productChannel;
            }
        }
    }


}